﻿//        $("#datapaging_table").click(function () {
//            var obj = $(this);
//            
//            $("#ds_value{{Id}}").val(obj.attr("value"));
//            $("#ds_text{{Id}}").val(obj.attr("text"));

//            //$("#ds_value{{Id}}").val("");
//            easyDialog.close();
//        });
if (!Array.prototype.forEach) {
    Array.prototype.forEach = function (callback, thisArg) {
        var T, k;
        if (this == null) {
            throw new TypeError(" this is null or not defined");
        }
        var O = Object(this);
        var len = O.length >>> 0; // Hack to convert O.length to a UInt32  
        if ({}.toString.call(callback) != "[object Function]") {
            throw new TypeError(callback + " is not a function");
        }
        if (thisArg) {
            T = thisArg;
        }
        k = 0;
        while (k < len) {
            var kValue;
            if (k in O) {
                kValue = O[k];
                callback.call(T, kValue, k, O);
            }
            k++;
        }
    };
}


$(function () {

    ///弹出现在窗口
    $("#button_select{{Id}}").click(function () {

        var ds_IsRadio = false;
        //加载选中的项
        function InitData() {
            var value = $("#ds_value{{Id}}").val();
            if (value != "") {
                $("#datapaging_table{{Id}} .ds_check").attr("checked", false);

                var list = value.split("|");
                list.forEach(function (str) {
                    if (str != "") {
                        $("#datapaging_table{{Id}} .ds_check[value=" + str + "]").attr("checked", true);
                    }
                });
            }
        }
        InitData();


        var valueList;
        var textList;
        function Initialization() {
            if (ds_IsRadio) {
                valueList = "";
                textList = "";
            } else {
                valueList = "|";
                textList = "|";
            }
        }
        if (ds_IsRadio) {
            $("#datapaging_table{{Id}} .ds_check").change(function () {
                if (this.checked) {
                    $("#datapaging_table{{Id}} .ds_check").each(function () {
                        this.checked = false;
                    });
                    this.checked = true;
                }
            });
        } else {
            Initialization();
        }

        $("#easyDialogYesBtn{{Id}}").click(function () {
            $("#datapaging_table{{Id}} .ds_check").each(function () {
                if (this.checked) {
                    var obj = $(this);
                    if (ds_IsRadio) {
                        valueList = obj.attr("value");
                        textList = obj.attr("text");
                        return false;
                    } else {
                        valueList += obj.attr("value") + "|";
                        textList += obj.attr("text") + "|";
                    }
                }

            });

            if (valueList == "" || valueList == "|") {
                //Initialization();
            } else {

            }
            $("#ds_value{{Id}}").val(valueList);
            $("#ds_text{{Id}}").val(textList);
            Initialization();
            easyDialog.close();
        });
        $("#easyDialogNoBtn{{Id}}").click(function () {
            easyDialog.close();
        });

        easyDialog.open({
            container: "div_{{Id}}",
            overlay: true
        });

    });
});